<?php
include('init.php');

$forum_id = $_GET['id'];
$sql = "SELECT forum_name FROM forums WHERE id=? LIMIT 1";
$sth = $dbh->prepare($sql);
$sth->execute(array($forum_id));
$forum = $sth->fetchObject();
if (!$forum){
	header('location:index.php');
	exit();
}

//breadcrumb
$breadcrumb = '<a href="index.php">'.$lang['HOME'].'</a>&nbsp;=>&nbsp;'.$forum->forum_name.'&nbsp;';

//contents
ob_start();
if (isset($_SESSION['userid'])){
echo '<a href="newtopic.php?id='.$forum_id.'">'.$lang['NEWTOPIC'].'</a>';
}
$sql = "SELECT * FROM topics WHERE forum_id = ? ORDER BY lastposted DESC";
$sth = $dbh->prepare($sql);
$sth->execute(array($forum_id));
echo '<table>';
foreach($sth->fetchAll(PDO::FETCH_OBJ) as $topic){
	echo '<tr><td><a href="viewtopic.php?id='.$topic->id.'">'.$topic->subject.'</a>';
	echo '<i>&nbsp;'.$lang['BY'].'&nbsp;'.$topic->user_name.".</i></td>\n";
	echo '<td><i>&nbsp;'.strftime($lang['timeformat'],$topic->lastposted).'&nbsp;';
	echo $topic->lastposter."</i></td></tr>\n";
}
echo '</table>';
$contents = ob_get_clean();

//write template
include('footer.php');
exit();
?>